﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// SharpenEffect Effect
    /// </summary>
    public class SharpenEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(SharpenEffect), 0);
        public static readonly DependencyProperty AmountProperty = DependencyProperty.Register("Amount", typeof(double), typeof(SharpenEffect), new UIPropertyMetadata(15.0, ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(SharpenEffect), new UIPropertyMetadata(0.0001, ShaderEffect.PixelShaderConstantCallback(1)));

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(SharpenEffect.InputProperty));
            }
            set
            {
                this.SetValue(SharpenEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Amount du Shader
        /// </summary>
        public double Amount
        {
            get
            {
                return ((double)this.GetValue(SharpenEffect.AmountProperty));
            }
            set
            {
                this.SetValue(SharpenEffect.AmountProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Width du Shader
        /// </summary>
        public double Width
        {
            get
            {
                return ((double)this.GetValue(SharpenEffect.WidthProperty));
            }
            set
            {
                this.SetValue(SharpenEffect.WidthProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique
        /// </summary>
        static SharpenEffect()
        {
            SharpenEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/Sharpen.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public SharpenEffect()
        {
            this.PixelShader = SharpenEffect._PixelShader;

            this.UpdateShaderValue(SharpenEffect.InputProperty);
            this.UpdateShaderValue(SharpenEffect.AmountProperty);
            this.UpdateShaderValue(SharpenEffect.WidthProperty);
        }

        #endregion
    }
}
